package com.example.managemyself.data.model;

import androidx.room.Entity;
import androidx.room.PrimaryKey;
import androidx.room.TypeConverters;

import com.example.managemyself.util.DateConverter;

import java.util.Date;

/**
 * 用户API密钥实体类
 * 用于存储用户的各种API密钥，如DeepSeek API Key
 */
@Entity(tableName = "user_api_keys")
@TypeConverters(DateConverter.class)
public class UserApiKey {
    
    @PrimaryKey(autoGenerate = true)
    private int id;
    
    private String userId;          // 用户ID
    private String apiType;         // API类型：deepseek, openai, etc.
    private String apiKey;          // API密钥
    private String apiName;         // API名称显示
    private boolean isActive;       // 是否激活
    private Date createdDate;       // 创建时间
    private Date updatedDate;       // 更新时间
    private String description;     // 描述信息
    
    // 构造函数
    public UserApiKey() {
        this.createdDate = new Date();
        this.updatedDate = new Date();
        this.isActive = true;
    }
    
    @androidx.room.Ignore
    public UserApiKey(String userId, String apiType, String apiKey, String apiName) {
        this();
        this.userId = userId;
        this.apiType = apiType;
        this.apiKey = apiKey;
        this.apiName = apiName;
    }
    
    // Getters and Setters
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    public String getUserId() {
        return userId;
    }
    
    public void setUserId(String userId) {
        this.userId = userId;
    }
    
    public String getApiType() {
        return apiType;
    }
    
    public void setApiType(String apiType) {
        this.apiType = apiType;
    }
    
    public String getApiKey() {
        return apiKey;
    }
    
    public void setApiKey(String apiKey) {
        this.apiKey = apiKey;
        this.updatedDate = new Date();
    }
    
    public String getApiName() {
        return apiName;
    }
    
    public void setApiName(String apiName) {
        this.apiName = apiName;
    }
    
    public boolean isActive() {
        return isActive;
    }
    
    public void setActive(boolean active) {
        isActive = active;
        this.updatedDate = new Date();
    }
    
    public Date getCreatedDate() {
        return createdDate;
    }
    
    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }
    
    public Date getUpdatedDate() {
        return updatedDate;
    }
    
    public void setUpdatedDate(Date updatedDate) {
        this.updatedDate = updatedDate;
    }
    
    public String getDescription() {
        return description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    // 工具方法
    public void updateKey(String newApiKey) {
        this.apiKey = newApiKey;
        this.updatedDate = new Date();
    }
    
    public boolean isDeepSeekKey() {
        return "deepseek".equalsIgnoreCase(this.apiType);
    }
    
    public boolean isExpired() {
        // 可以根据需要实现过期逻辑
        return false;
    }
    
    @Override
    public String toString() {
        return "UserApiKey{" +
                "id=" + id +
                ", userId='" + userId + '\'' +
                ", apiType='" + apiType + '\'' +
                ", apiName='" + apiName + '\'' +
                ", isActive=" + isActive +
                ", createdDate=" + createdDate +
                '}';
    }
} 